package com.medical_houduan.controller;

import com.medical_houduan.commons.Result;
import com.medical_houduan.dto.DrugCompanyDTO;
import com.medical_houduan.service.DrugCompanyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/company")
@Tag(name = "医药公司接口",description = "这个接口用于医药公司")
public class DrugCompanyController {
    @Autowired
    DrugCompanyService drugCompanyService;

    @GetMapping("/getDrugCompany")
    @Operation(summary = "获取公司数据",description = "获取数据库所有的医药公司，关键字可选")
    public Result getCompanies(@RequestParam(value = "currentPage",defaultValue = "1",required = false) Integer currentPage,
                               @RequestParam(value = "pageSize",defaultValue = "10",required = false) Integer pageSize,
                               @RequestParam(value = "key",required = false) String keyword){
        return drugCompanyService.getCompanies(currentPage,pageSize,keyword);
    }

    @PostMapping("/addDrugCompany")
    @Operation(summary = "添加医药公司",description = "通过公司名称和电话添加医药公司")
    public Result addCompany(@RequestBody DrugCompanyDTO drugCompanyDTO){
        return drugCompanyService.addCompanyService(drugCompanyDTO);
    }


    @GetMapping("/deleteDrugCompanyById/{Id}")
    @Operation(summary = "删除指定的医药公司",description = "通过公司Id删除医药公司")
    public Result deleteCompany(@PathVariable("Id") Long companyId){
        return drugCompanyService.deleteCompanyService(companyId);
    }

    @PostMapping("/ModifyDrugCompany")
    @Operation(summary = "修改指定的医药公司",description = "通过DrugCompanyDTO对象删除医药公司")
    public Result modifyCompany(@RequestBody DrugCompanyDTO drugCompanyDTO){
        return drugCompanyService.modifyCompanyService(drugCompanyDTO);
    }
}
